package com.example.genshintj;

import android.os.Bundle;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;
import android.content.Intent;
import android.widget.ImageView;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.material.bottomnavigation.BottomNavigationView;

public class MainActivity extends AppCompatActivity {
    TextView textViewWelcome;
    private ViewPager2 viewPager;
    private BottomNavigationView bottomNavigationView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textViewWelcome = findViewById(R.id.textViewWelcome);
        viewPager = findViewById(R.id.viewPager);
        bottomNavigationView = findViewById(R.id.bottomNavigationView);


        viewPager.setAdapter(new FragmentStateAdapter(this) {
            @NonNull
            @Override
            public Fragment createFragment(int position) {
                switch (position) {
                    case 0:
                        return new mengde();
                    case 1:
                        return new liyue();
                    case 2:
                        return new daoqi();
                    case 3:
                        return new shoucang();
                    default:
                        return new mengde();
                }
            }

            @Override
            public int getItemCount() {
                return 4;
            }
        });

        viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                switch (position) {
                    case 0:
                        bottomNavigationView.setSelectedItemId(R.id.nav_home);
                        break;
                    case 1:
                        bottomNavigationView.setSelectedItemId(R.id.nav_dashboard);
                        break;
                    case 2:
                        bottomNavigationView.setSelectedItemId(R.id.nav_notifications);
                        break;
                    case 3:
                        bottomNavigationView.setSelectedItemId(R.id.nav_profile);
                        break;
                }
            }
        });
        bottomNavigationView.setOnNavigationItemSelectedListener(item -> {
            switch (item.getItemId()) {
                case R.id.nav_home:
                    viewPager.setCurrentItem(0);
                    return true;
                case R.id.nav_dashboard:
                    viewPager.setCurrentItem(1);
                    return true;
                case R.id.nav_notifications:
                    viewPager.setCurrentItem(2);
                    return true;
                case R.id.nav_profile:
                    viewPager.setCurrentItem(3);
                    return true;
            }
            return false;
        });


        String username = getIntent().getStringExtra("USERNAME");
        if (username != null) {
            textViewWelcome.setText("欢迎: " + username);
        }
    }
    public void onButtonClick(View view) {
        Intent intent = new Intent(this, xiangqing.class);
        switch (view.getId()) {
            case R.id.button1:
                intent.putExtra("content_id", 1);
                break;
            case R.id.button2:
                intent.putExtra("content_id", 2);
                break;
            case R.id.button3:
                intent.putExtra("content_id", 3);
                break;
            case R.id.button4:
                intent.putExtra("content_id", 4);
                break;
            case R.id.button5:
                intent.putExtra("content_id", 5);
                break;
            case R.id.button6:
                intent.putExtra("content_id", 6);
                break;
            case R.id.button7:
                intent.putExtra("content_id", 7);
                break;
            case R.id.button8:
                intent.putExtra("content_id", 8);
                break;
            case R.id.button9:
                intent.putExtra("content_id", 9);
                break;
            // 可以添加更多按钮的处理
        }
        startActivity(intent);
    }
}